﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

/// <summary>
/// Descripción breve de UIBindable
/// </summary>
public class UIBindable
{
    public static void Bind(CheckBox c, bool estado)
    {
        c.Checked = estado;
    }
    public static void Bind(Literal c, String text)
    {
        c.Text = text;
    }
    public static void Bind(Label c, String text)
    {
        c.Text = text;
    }
    public static void Bind(TextBox c, String text)
    {
        c.Text = text;
    }
    public static void Bind(HiddenField c, String text)
    {
        c.Value = text;
    }
    public static void Bind(ListControl c, IEnumerable t)
    {
        Bind(c, t, "Codigo", "Descripcion");
    }

    public static void Bind(ListControl c, IEnumerable t,bool insertarSeleccion)
    {
        Bind(c, t, "Codigo", "Descripcion",insertarSeleccion);
    }

    public static void Bind(ListControl c, IEnumerable t, String value, String text)
    {
        c.DataSource = t;
        c.DataValueField = value;
        c.DataTextField = text;
        c.DataBind();
    }
    public static void Bind(ListControl c, IEnumerable t, String value, String text, bool insertarSeleccion)
    {
        c.DataSource = t;
        c.DataValueField = value;
        c.DataTextField = text;
        c.DataBind();
        if (insertarSeleccion)
            c.Items.Insert(0, new ListItem("Seleccione", String.Empty));
    }


    public static void Bind(ListControl c, IEnumerable t, String value, String text, Type tipo)
    {

        c.DataSource = t;
        c.DataValueField = value;
        c.DataTextField = text;
        c.DataBind();
    }
    public static void Bind(GridView c, IEnumerable t)
    {
        c.DataSource = t;
        c.DataBind();
    }
    public static void Bind(CheckBoxList c, IEnumerable t, String value, String text)
    {
        c.DataSource = t;
        c.DataValueField = value;
        c.DataTextField = text;
        c.DataBind();
    }
    public static void InsertarSeleccionar(ListControl c)
    {
        c.Items.Insert(0, new ListItem("Seleccione", String.Empty));
    }
    public static void InsertarNinguno(ListControl c)
    {
        c.Items.Insert(0, new ListItem("Ninguno", string.Empty));
    }
}
